389A - Fox and Number Game - CodeForces Solution


greedy math *1000

Please click on ads to support us..

Python Code:

n = int(input())
numbers = [int(x) for x in input().split()]


while True:
    x = numbers.index(ma := max(numbers))
    y = numbers.index(mi := min(numbers))
    if x != y:
        numbers[x] = ma - mi
    else:
        break
print(sum(numbers))

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define mod (int)1e9+7
using namespace std;
// Code By VibhuGodson
ll gcd(ll a,ll b){
    return __gcd(a,b);
}
int main(){
    ll t=1;
    // cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll x;
        ll m=n;
        n--;cin>>x;
        ll y;
        while(n--) {cin>>y;x=gcd(x,y);}
        cout<<m*x<<endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman
320B - Ping-Pong (Easy Version)
948A - Protect Sheep
387A - George and Sleep
53A - Autocomplete
1729G - Cut Substrings
805B - 3-palindrome
805C - Find Amir
676C - Vasya and String
1042B - Vitamins
1729F - Kirei and the Linear Function
25D - Roads not only in Berland
1694A - Creep
659F - Polycarp and Hay
1040A - Palindrome Dance
372A - Counting Kangaroos is Fun